package ScanLineAlghorithms.RectanglesUnion;

import DataModel.SegmentTree.SegmentTreeNode;
import DataModel.SegmentTree.SegmentTreeNodeGenData;
/**
 * Class which  models additional data stored in every segment tree node in order to 
 * calculate rectangles union.
 * Reference: Schamos and Preparata: Introduction to Alghorithms, Chapter 8 -Geometry of rectangles.
 * @author Guy
 *
 */
public class TreeNodeAdditionalData implements SegmentTreeNodeGenData {
	public enum STATUS {EMPTY , FULL , PARTIAL}
	private SegmentTreeNode tNode = null;
	private STATUS s=STATUS.EMPTY;
	
	public TreeNodeAdditionalData(SegmentTreeNode n) {
		tNode = n;
	}
	public STATUS getStatus() {
		return s;
	}
	public void update() {
		
		if (tNode.getData().size()>0) {
			s=STATUS.FULL;
			return;
		}
		//node is a leaf
		if (tNode.leftSon() == null) {
			s=STATUS.EMPTY;
			return;
		}
		if (((TreeNodeAdditionalData)tNode.leftSon().getGenericData()).getStatus() == STATUS.EMPTY 
			&& ((TreeNodeAdditionalData)tNode.rightSon().getGenericData()).getStatus() == STATUS.EMPTY) {
			s = STATUS.EMPTY;
			return;
		} 
		s= STATUS.PARTIAL;
		return;
		
	}

}
